<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>拍卖列表</title>

    <link href="../../resource/css/bootstrap.min.css?v=3.3.5" rel="stylesheet"
          th:href="@{/resource/css/bootstrap.min.css?v=3.3.5}"/>
    <link href="../../resource/hotui/css/font-awesome.min.css" th:href="@{/resource/hotui/css/font-awesome.min.css}"
          rel="stylesheet">
    <!-- Morris -->
    <link href="../../resource/hotui/css/plugins/morris/morris-0.4.3.min.css"
          th:href="@{/resource/hotui/css/plugins/morris/morris-0.4.3.min.css}" rel="stylesheet">
    <link href="../../resource/css/animate.min.css" rel="stylesheet" th:href="@{/resource/css/animate.min.css}"/>
    <link href="../../resource/hotui/css/style.min-1.0.8.css" th:href="@{/resource/hotui/css/style.min-1.0.8.css}"
          rel="stylesheet">
    <link href="../../resource/hotui/css/hotui.style.override.css"
          th:href="@{/resource/hotui/css/hotui.style.override.css}" rel="stylesheet"/>
    <link href="../../resource/hotui/js/plugins/datetimepick/css/daterangepicker.css"
          th:href="@{/resource/hotui/js/plugins/datetimepick/css/daterangepicker.css}" rel="stylesheet"/>


    <style type="text/css">
        .hr-line-dashed {
            margin: 10px 0;
            height: 1px;
            border-top: 1px dashed #e7eaec;
            background-color: #fff;
            color: #fff;
        }
    </style>
</head>

<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight tooltip-demo">
    <!--search-->
    <form role="form" id="searchForm" class="search-panel" method="get"
          th:object="${condition}">
        <div class="row">
            <div class="col-lg-12">
                <div class="ibox">
                    <div class="ibox-content">
                        <div class="form-inline">
                            <input type="hidden" th:value="${pageIndex}" name="pageIndex"/>
                            <div class="form-group m-r-sm">
                                <label class=" control-label" for="keyword">名称：</label>
                                <input type="text" class="form-control input-sm mb10" id="keyword"
                                       th:value="*{keyword}"
                                       name="keyword" placeholder="名称" style="width: 156px;"/>
                            </div>
                            <div class="form-group m-r-sm">
                                <button type="button" onclick="listHandler.search(1)"
                                        class="btn btn-primary btn-sm m-b-none searchBtn">筛选
                                </button>
                                <button type="button" onclick="listHandler.searchAll()"
                                        class="btn btn-primary btn-sm m-b-none">重置
                                </button>
                            </div>

                            <div class="form-group m-r-sm" style="float: right;">
                                <button type="button" onclick="listHandler.save(0)"
                                        class="btn btn-primary btn-sm m-b-none searchBtn">添加
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>
    <!--search-->

    <!--list-->
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins m-b-none">
                <div class="tabs-container">
                    <div class="tab-content">
                        <div class="tab-pane active">
                            <div class="panel-body table-responsive">
                                <table class="table table-bordered table-hover table-center">
                                    <thead>
                                    <tr>
                                        <th></th>
                                        <th>标题</th>
                                        <th>市场价格</th>
                                        <th>所需积分</th>
                                        <th>库存</th>
                                        <th>限兑数量</th>
                                        <th>已兑数量</th>
                                        <th>上架</th>
                                        <th>操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>

                                    <tr th:each="item:${list}">
                                        <td>
                                            <img th:src="${@resourceService.get(item.thumbnail).getURI()}"
                                                 style="width: 50px;height: 50px;border-radius: 10px"
                                                 src="../../resource/img/p1.jpg">
                                        </td>
                                        <td th:text="${item.title}"></td>
                                        <td th:text="${item.price}"></td>
                                        <td th:text="${item.integral}"></td>
                                        <td th:text="${item.store}"></td>
                                        <td th:text="${item.limitExchange<=0?'不限购':item.limitExchange}"></td>
                                        <td th:text="${item.exchangeCount}"></td>
                                        <td th:class="${item.published?'color-primary':'color-danger'}"
                                            th:text="${item.published?'是':'否'}"></td>
                                        <td>
                                            <a th:href="|javascript:listHandler.save(${item.id})|"
                                               href="javascript:listHandler.save(1)">编辑</a>
                                            <a th:if="${item.published}" href="javascript:listHandler.publishToggle(1)"
                                               th:href="|javascript:listHandler.publishToggle(${item.id})|">下架</a>
                                            <a th:if="${!item.published}" href="javascript:listHandler.publishToggle(1)"
                                               th:href="|javascript:listHandler.publishToggle(${item.id})|">>上架</a>
                                            <a href="javascript:listHandler.modifyStore(1)"
                                               th:href="|javascript:listHandler.modifyStore(${item.id})|">库存修改</a>
                                        </td>
                                    </tr>
                                    </tbody>
                                </table>
                                <p style="float: left; margin: 20px 0;">
                                    共<span th:text="${totalRecords}"></span>条记录，当前第<span th:text="${pageIndex}"></span>/<span
                                        th:text="${totalPages==0?1:totalPages}"></span>，每页20条记录
                                </p>
                                <ul style="float: right;" class="pagination pagination-split">
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>

            </div>
        </div>
    </div>
</div>

<!--基础框架js-->
<script src="../../resource/js/jquery.min.js?v=2.1.4" th:src="@{/resource/js/jquery.min.js?v=2.1.4}"></script>
<script src="../../resource/js/bootstrap.min.js?v=3.3.5" th:src="@{/resource/js/bootstrap.min.js?v=3.3.5}"></script>
<script src="../../resource/hotui/js/hot/bootstrap.hot.extra-utils.js"
        th:src="@{/resource/hotui/js/hot/bootstrap.hot.extra-utils.js(123123)}"></script>
<script src="../../resource/hotui/js/hot/bootstrap.hot.extra-init.js"
        th:src="@{/resource/hotui/js/hot/bootstrap.hot.extra-init.js}"></script>
<script src="../../resource/hotui/js/content.min.js" th:src="@{/resource/hotui/js/content.min.js}"></script>
<script src="../../resource/lib/moment.min.js" th:src="@{/resource/lib/moment.min.js}"></script>
<script src="../../resource/hotui/js/plugins/datetimepick/js/daterangepicker.js"
        th:src="@{/resource/hotui/js/plugins/datetimepick/js/daterangepicker.js}"></script>


<script type="text/javascript" th:inline="javascript">
    const pageIndex = /*[[${pageIndex}]]*/  1;
    const totalPages = /*[[${totalPages}]]*/  0;
    const pageUri = /*[[@{/integral/product/list}]]*/  "";
    const apiUri = /*[[@{/integral/product}]]*/  "";
</script>
<script>
    $(function () {
        //初始化分页
        let pageinate = new hot.paging(".pagination", pageIndex, totalPages, 7);

        pageinate.init(function (p) {
            listHandler.search(p);
        });
        $(document).keyup(function (event) {
            if (event.keyCode === 13) {
                $(".searchBtn").trigger("click");
            }
        });
    });

    let listHandler = {
        search: function (pageIndex) {
            $("input[name=pageIndex]").val(pageIndex);
            $("#searchForm").submit();
        },
        searchAll: function () {
            window.location.href = pageUri;
        },
        save: function (id) {
            let uri = apiUri + "/save?productId=" + id;
            hot.iframeModal(uri, window.innerWidth * 0.6 + "px", window.innerHeight * 0.95 + "px", '商品编辑');
        },
        publishToggle: function (id) {
            hot.ajax(apiUri + "/publishToggle", {
                productId: id
            }, function (apiResult) {
                if (apiResult.resultCode === 2000) {
                    hot.tip.success("操作成功", function () {
                        window.location.reload();
                    })
                } else {
                    hot.tip.error("操作失败--" + apiResult.resultMsg);
                }
            }, function () {
            }, "post");
        },
        modifyStore: function (id) {
            layer.prompt({title: '库存修改，负数为减少库存', formType: 0}, function (text, index) {
                if (text.length === 0) {
                    hot.tip.msg("请输入需要修改的库存");
                }

                let requestData = {
                    productId: id,
                    num: text
                };

                hot.ajax(apiUri + "/modifyStore", requestData, function (apiResult) {
                    if (apiResult.resultCode === 2000) {
                        hot.tip.success("操作成功", function () {
                            layer.close(index);
                            window.location.reload();
                        })
                    } else {
                        hot.tip.error("操作失败--" + apiResult.resultMsg);
                    }
                }, function () {
                }, "post", 300);

            });
        }
    }
</script>
</body>
</html>
